<template>
	<div class="edu-page-warp">
		<inner-breadcrumb v-model="pathKey" :path="path" v-show="pathKey!='main'"></inner-breadcrumb>
		<template v-if="pathKey=='main'">
			<condition-card @reset="reset" @search="onSubmit" v-if="isGraduate" label-width="120px">
				<el-row>
					<el-col :span="8" v-if="global.isAnyTeacher">
						<el-form-item :label="$t('管理部门')">
							<el-select v-model="queryForm.managerDeptId" style="width: 100%;">
								<el-option
									v-for="item in options.managerDeptIds"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('course.college')">
							<DictSelect
                                v-model="queryForm.college"
                                :data="options.college"
								:plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('label.trainingLevel')">
							<DictSelect
                                v-model="queryForm.trainingLevel"
                                :data="options.trainingLevel"
								:plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('course.courseProperty')">
							<DictSelect
                                v-model="queryForm.nature"
                                :data="options.nature"
								:plzSelect="true"
								@change="changeNatureForm"
                            ></DictSelect>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('course.courseCategory')">
							<DictSelect
                                v-model="queryForm.label"
                                :data="options.newLabel"
								:plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('course.teachingLanguage')">
							<DictSelect
                                v-model="queryForm.teachingLanguage"
                                :data="options.teachingLanguage"
								:plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('course.enabled')">
							<DictSelect
                                v-model="queryForm.enabled"
                                :data="options.enabled"
								:plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('开课学期')">
								<DictSelect
                                v-model="queryForm.term"
                                :data="options.term"
								:plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('审核状态')">
								<DictSelect
                                v-model="queryForm.status"
                                :data="options.status"
                                :plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('是否跨院系课程')">
								<DictSelect
                                v-model="queryForm.crossCollege"
                                :data="options.enabled"
                                :plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
				</el-row>
			</condition-card>
			<el-card shadow="never">
				<div class="edu-page-title" style="width:100px;margin-bottom:16px;float:left">{{$t("course.CourseApplication")}}</div>
				<div class="float-left" style="color:red;line-height:22px">
					提示：系统申请新开课前需填好此新开课申请表格(请点击：下载模板)，请规范填写并签字后将此表原件交开课学院存档。
				</div>
				<div class="edu-opertion-bar" style="margin-bottom:16px;clear:both" v-if="isEnable&&isGraduate">
					<div class="float-left">
						<el-input
							v-model="queryForm.condition"
							:placeholder="$t('course.inputCourseTip')"
							style="width:240px"
							@keyup.enter.native="onSubmit"
						>
							<i
								class="el-icon-search"
								slot="suffix"
								style="margin-top:10px;cursor:pointer"
								@click="onSubmit"
							></i>
						</el-input>
					</div>					
					<div class="float-right">
						<export-button v-if="!this.global.isStudent" :queryForm="queryForm" :chooseCourses="chooseCourses" exType="1">{{$t("导出PDF")}}</export-button>
						<export-button v-if="!this.global.isStudent" :queryForm="queryForm" :chooseCourses="chooseCourses" exType="2">{{$t("导出Word")}}</export-button>
						<el-button @click="showDeleteDialog" type="danger">{{$t("message.delete")}}</el-button>
						<el-button @click="exportExcel">{{$t("message.export")}}</el-button>
						<el-button @click="down">{{$t("message.down")}}</el-button>
						<el-button type="primary" @click="showAddDialog">{{$t("message.add")}}</el-button>
					</div>
				</div>
				<edu-table
					:data="courses"
					@page-change="handleCurrentChange"
					:total="queryForm.total_"
					:pageSize="queryForm.pageSize_"
					:current-page="queryForm.pageNum_"
					@selection-change="chooseCourse"
				>
					<edu-table-column :label="$t('course.college')" prop="college" width="200"/>
					<edu-table-column :label="$t('course.courseCode')" prop="code" width="120"/>
					<edu-table-column :label="$t('course.courseName')" width="240">
						<template slot-scope="props">
							<span>{{getNameByLanguage(props.row)}}</span>
						</template>
					</edu-table-column>
					<edu-table-column :label="$t('course.score')" prop="credits" width="65"/>
					<edu-table-column :label="$t('课时')" prop="period" width="65"/>
					<edu-table-column :label="$t('course.term')" prop="term" width="80"/>
					<edu-table-column :label="$t('course.courseProperty')" prop="nature"/>
					<edu-table-column :label="$t('是否跨院系课程')" width="130">						
						<template slot-scope="props">{{props.row.crossCollege == null?"":(props.row.crossCollege == 1?'是':'否')}}</template>
					</edu-table-column>
					<edu-table-column :label="$t('message.applyDate')" width="110">
						<template slot-scope="props">{{formatDate(props.row.applyAt)}}</template>
					</edu-table-column>
					<edu-table-column :label="$t('message.checkDate')" width="110">
						<template slot-scope="props">{{formatDate(props.row.createdAt||props.row.updatedAt)}}</template>
					</edu-table-column>
					<edu-table-column :label="$t('message.status')" fixed="right" width="110">
						<template slot-scope="props">
							<el-tag
								v-if="props.row.status==3"
								type="success"
								size="mini"
							>{{getStatusText(props.row)}}</el-tag>
							<el-tag
								v-if="props.row.status==2"
								type="info"
								size="mini"
							>{{getStatusText(props.row)}}</el-tag>
							<el-tag
								v-if="props.row.status==1"
								type="warning"
								size="mini"
							>{{getStatusText(props.row)}}</el-tag>
							<el-tag
								v-if="props.row.status==0"
								type="warning"
								size="mini"
							>{{getStatusText(props.row)}}</el-tag>
						</template>
					</edu-table-column>
					<edu-table-column prop="courseCode" :label="$t('message.operating')" :width="btnWidth" fixed="right">
						<template slot-scope="props">
							<el-button
								type="text"
								@click="courseEdit(props.row, 'detail')"
								size="mini"
							>{{$t('shortTermApprove.check')}}</el-button>
							<el-button
								v-if="props.row.status==null||props.row.status==0||props.row.status==1"
								type="text"
								@click="checkCourse(props.row)"
								size="mini"
							>{{$t('message.submit')}}</el-button>
							<el-button
								v-if="props.row.status==null||props.row.status==0||props.row.status==1"
								type="text"
								@click="courseEdit(props.row, 'edit')"
								size="mini"
							>{{$t('message.edit')}}</el-button>
							<el-button
								v-if="props.row.status==null||props.row.status==0||props.row.status==1"
								type="text"
								@click="courseDelete(props.row)"
								size="mini"
							>{{$t('message.delete')}}</el-button>
						</template>
					</edu-table-column>
				</edu-table>
			</el-card>
		</template>
		<CourseOperation
			v-if="pathKey=='check' || pathKey=='add' || pathKey=='edit' "
			:pathKey="pathKey"
			:options="options"
			:courseForm="courseForm"
			:heardTitle="heardTitle"
			:managerDeptId="managerDeptId"
			:showCourseCode="showCourseCode"
			@back="pathKey='main'"
			:showCrossTerm="false"
			:committee="true"
		></CourseOperation>
	</div>
</template>
<script>
import {
	getCourseList,
	getpath,
	down,
} from "common/src/api/courseTemplate";
import {
	addCourse,
	editCourse,
	deleteCourse,
	getCourseById,
	generateExcel,
	apporoveCourse,
	getFacultys,
	getSubjectMajorRoleByCommittee,
	getSubjectMajorCommitteeByDept
} from "common/src/api/resource/course";
import { findListByFaculty } from "common/src/api/resource/teachers";
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import CourseOperation from "./component/CourseOperation";
import ExportButton from "./component/ExportButton";
import examinationStudentsApi from "common/src/api/welcomeService/examinationStudents";
import mixin from 'common/src/mixins/index';
var defaultCourseForm = {
	id: null,
	code: "", //课程编码
	name: "", //课程名称
	nameEn: "", //课程名称英文
	college: "", //学院
	trainingLevel: "", //培养层次
	formLearning: "", //学习形式(课程类型)
	credits: "", //学分
	period: "", //课时
	label: "", //课程分类
	isElective: "",
	outlineWriter: "",
	outlineWriterEn: "",
	outlineApprover: "",
	naturePurpose: "",
	basicRequire: "",
	schedule: "", //获取课程内容与学时分配
	scheduleEn: "", //课程内容与学时分配(英文)
	experiment: "", //实验及实践性环节
	experimentEn: "",
	establishOn: "",
	introductionCourse: "", //简介
	engIntroductionCourse: "", //英文简介
	cause: "",
	remark: "",
	term: "", //研究生字段，开课学期
	nature: "", //研究生字段，课程性质
	scoreType: "", //研究生字段，成绩类型
	teachingLanguage: "", //研究生字段，授课语言
	majorList: [], //研究生字段，专业中文
	majorTextI18n:null,
	majorEnList: [], //研究生字段，专业英文
	enabled: 1, //研究生字段，课程使用状态
	crossTerm: 0, //研究生字段，是否跨学期
	assessmentMode: "", //考试方式,
	headTeacher: "", //主讲人
	teachersList: [], //其他讲课人
	teachModeI18n:"",
	teachModeList: [], //教学方式
	precourse: "", //预修课程
	precourseEn: "", //预修课程(英文)Prerequisite
	teacherTermInfo: "", //教师团队介绍
	requirement: "", //教学目标与要求
	requirementEn: "", //教学目标与要求英文
	crossCollege: "", //研究生字段，是否跨院系课程
	majorText:"",//适用专业
	subjectMajorCode:"",//学科专业委员会代码
	appointUserCode:"",//指定审核人code
};
export default {
	name: "courseManage",
	mixins: [mixin],
	components: {
		CourseOperation,
		ExportButton
	},
	watch: {
		pathKey(val) {
			if (val == "main") {
				this.onSubmit();
			}
		},
		'queryForm.managerDeptId' (val) {
			this.isGraduate = this.queryForm.managerDeptId != "1"
			this.onSubmit()
		}
	},

	data() {
		return {
			pathKey: "main",
			showCourseCode:false,
			path: {
				label: this.$t("courses.courseManagement"),
				key: "belong",
				disable: true,
				children: [
					{
						label: this.$t("courses.courseApply"),
						key: "main",
						children: [
							{
								label: this.$t("courses.courseDetails"),
								key: "check"
							},
							{
								label: this.$t("courses.addCourse"),
								key: "add"
							},
							{
								label: this.$t("courses.editCourse"),
								key: "edit"
							}
						]
					}
				]
			},
			isGraduate: false,
			courseStatus: {
				DISABLE: 0,
				DRAFT: 1,
				CHECKING: 2,
				PUBLISH: 3
			},
			cachmanagerDeptId:"",
			queryForm: {
				teachingLanguage: "",
				college: "", //学院
				trainingLevel: "", //培养层次
				formLearning: "", //学习形式(课程类型)
				nature: "", //课程性质
				isElective: "", //公共选修课
				label: "", //课程分类
				condition: "", //课程代码或课程名称
				enabled: "", //是否使用
				pageSize_: 20,
				pageNum_: 1,
				total_: 0,
				approvalFlag: "0",
				managerDeptId: "", //管理部门
				term:"",//开课学期
				status:"",//审核状态
				crossCollege:""//是否跨院系课程
			},
			managerDeptId: "",
			courseForm: JSON.parse(JSON.stringify(defaultCourseForm)),
			options: {
				college: [],
				trainingLevel: [],
				formLearning: [],
				nature: [], //课程性质
				isElective: [], //公共选修课，（1或0)
				label: [], //课程分类
				newLabel: [],
				tableLabel: [],
				term: [],//开课学期
				scoreType: [], //成绩类型
				teachingLanguage: [], //授课类型
				enabled: [], //研究生字段，课程使用状态
				crossTerm: [], //研究生字段，是否跨学期
				dialogLabelId: [], //弹框的课程分类
				assessmentMode: [], //考试方式
				majorList: [],
				teacherList: [],
				departments: [], //部门
				teachModeList: [], //教学方式
				subjectMajorCode:[],//学科专业委员会
				appointUserCode:[],//指定审核人
				managerDeptIds:[],
				status:[			
					{label:this.$t("message.toBeSubmitted"),value:1},
					{label:"待审核",value:21},
					{label:"待教学院长审核",value:22},
					{label:"待学校审核",value:23},
					{label:"已通过",value:3},
					{label:"已驳回",value:0}
				] //审核状态 (1待提交，2待审核，3通过，0驳回)
			},
			courses: [], //课程列表
			chooseCourses: [], //选中课程列表
			editCourseId: "", //当前编辑课程Id
			isEnable: false,
			majorDataEn: "",
			headTeacherCondition: null,
			teacherCondition: null,
			manageDptIds:[],
			btnWidth:60
		};
	},
	mounted() {
		if (this.global.isAnyTeacher) {
			//当前页目前仅支持研究生，直接过滤本科
			this.manageDptIds =  this.global.currentUser.manageDptIds.filter(val=>val!='1');
			if(this.manageDptIds.length>0){
				this.cachmanagerDeptId=this.manageDptIds[0]
				this.isGraduate = this.manageDptIds[0] != "1";
			}
		}else{
			this.isGraduate = this.global.currentUser.currentManageDptId != "1";
		}
		this.init();
	},
	methods: {
		init() {
			let yes = {
					label: this.$t("message.yes"),
					value: 1
				},
				no = {
					label: this.$t("message.no"),
					value: 0
				};
			this.options.enabled.push(yes);
			this.options.enabled.push(no);
			this.options.crossTerm.push(yes);
			this.options.crossTerm.push(no);
			//筛选条件字典查询
			let data = {
				lang: this.$store.getters.language || "cn",
				type: "allChild",
				keys: [
					"X_PYCC",
					//"X_YX",
					"X_XXXS",
					"X_CJJL",
					"X_SKYY",
					"X_KKXQ",
					"X_KSLX",
					"G_ZY",
					"X_KCXZ",
					"X_KCFL",
					"X_JXFS",
					"X_GLBM"
				]
			};

			queryDic(data).then(res => {
				if (res.code == 200) {
					let cObj = {};
					UTILS.fillSelect(
						{
							trainingLevel: "X_PYCC",
							//college: "X_YX",
							formLearning: "X_XXXS",
							scoreType: "X_CJJL",
							teachingLanguage: "X_SKYY",
							term: "X_KKXQ",
							assessmentMode: "X_KSLX",
							majorList: "G_ZY",
							nature: "X_KCXZ",
							label: "X_KCFL",
							departments: "X_GLBM",
							teachModeList: "X_JXFS",
							managerDeptIds:"X_GLBM"
						},
						res.data,
						this.options
					);
					if(this.global.isAnyTeacher){
						this.options.managerDeptIds=this.options.managerDeptIds.filter(dept=>{
							return this.manageDptIds.includes(dept.value)
						})
						this.options.trainingLevel = this.options.trainingLevel.filter(tr =>{
							return tr.value == '4' || tr.value == '6'
						})
						this.options.formLearning = this.options.formLearning.filter(form => form.value != 3)
					}
					//查询开课学院
					getFacultys(this.isGraduate).then(res => {
						if (res.code == 200) {
							let depts =res.data.filter(c => c.deptCode != "-10000");
							this.options.college = depts;
							this.options.college.forEach(c => {
								c.value = c.deptCode;
								c.label =
									"en" == this.$store.getters.language
										? c.deptNameEn
										: c.deptName;
							});
						}
					});
					this.isEnable = true;
					this.$nextTick(re =>{
						this.queryForm.managerDeptId = this.cachmanagerDeptId
						this.onSubmit();
					})
				}
			});

			//查询专业的英文
			let majorDataEn = {
				lang: "en",
				type: "allChild",
				keys: ["G_ZY"]
			};
			queryDic(majorDataEn).then(res => {
				if (res.code == 200) {
					this.majorDateEn = res.data["G_ZY"];
				}
			});
		},
		reset() {
			this.options.newLabel.length = 0;
			this.queryForm.college = "";
			this.queryForm.trainingLevel = "";
			this.queryForm.formLearning = "";
			this.queryForm.nature = "";
			this.queryForm.isElective = "";
			this.queryForm.label = "";
			this.queryForm.condition = "";
			this.queryForm.enabled = "";
			this.queryForm.teachingLanguage = "";
			this.queryForm.term ="";
			this.queryForm.status = "";
			this.queryForm.crossCollege =""
			this.onSubmit();
		},
		onSubmit() {
			if (this.isGraduate) {
				this.getCourseList();
			} else {
				this.queryForm.total_ = 0;
				this.courses = [];
				this.btnWidth=0;
			}
		},
		formatDate(timenumber) {
			return timenumber ? moment(timenumber).format("YYYY-MM-DD") : "";
		},
		handleCurrentChange(val) {
			this.queryForm.pageNum_ = val.pageNum;
			this.queryForm.pageSize_ = val.pageSize;
			this.getCourseList();
		},
		//课程性质选中显示相应的课程分类
		changeNatureForm(val) {
			this.options.newLabel = [];
			this.queryForm.label = "";
			let obj = [];
			let labels = this.options.label;
			labels.forEach(item => {
				if (val == "1") {
					if (
						item.value == "01" ||
						item.value == "02" ||
						item.value == "03" ||
						item.value == "07"
					) {
						obj.push({ label: item.label, value: item.value });
					}
				} else if (val == "2") {
					if (
						item.value == "04" ||
						item.value == "05" ||
						item.value == "06" ||
						item.value == "07"
					) {
						obj.push({ label: item.label, value: item.value });
					}
				} else {
					if (item.value == "08" || item.value == "09") {
						obj.push({ label: item.label, value: item.value });
					}
				}
			});
			this.options.newLabel = obj;
		},
		changeSubMajor(val){
            this.options.appointUserCode = [];
            if(val){
                getSubjectMajorRoleByCommittee(val).then(res =>{
                    if (res.code == 200 && res.data.length > 0) {
                        for (const item of res.data) {
                            this.options.appointUserCode.push({
                                label: item.userName+'('+item.userCode+')',
                                value: item.userCode
                            });
                        }
                    }
                })
            }
        },
		changeNatureEdit(val) {
			this.options.tableLabel = [];
			let obj = [];
			let labels = this.options.label;
			labels.forEach(item => {
				if (val == "1") {
					if (
						item.value == "01" ||
						item.value == "02" ||
						item.value == "03" ||
						item.value == "07"
					) {
						obj.push({ label: item.label, value: item.value });
					}
				} else if (val == "2") {
					if (
						item.value == "04" ||
						item.value == "05" ||
						item.value == "06" ||
						item.value == "07"
					) {
						obj.push({ label: item.label, value: item.value });
					}
				} else {
					if (item.value == "08" || item.value == "09") {
						obj.push({ label: item.label, value: item.value });
					}
				}
			});
			this.options.tableLabel = obj;
		},		
		//获取课程列表
		getCourseList() {
			getCourseList(this.queryForm).then(response => {
				if (response.code == 200) {
					this.courses = response.data.list;
					if(this.courses.some(c=>c.status==null||c.status==0||c.status==1)){
						this.btnWidth=170
					}else{
						this.btnWidth=60
					}
					this.queryForm.total_ = response.data.total_;
				} else {
					throw response.code;
				}
			});
		},
		chooseCourse(val) {
			this.chooseCourses = val;
		},
		//课程编辑
		courseEdit(row, type) {
			this.editCourseId = row.id;
			//获取该课程详细信息
			getCourseById(this.editCourseId).then(response => {
				if (response.code == 200) {
					this.changeNatureEdit(response.data.nature);
					this.changeSubMajor(response.data.subjectMajorCode);
					getSubjectMajorCommitteeByDept(response.data.college).then(res=>{
                        if(res.code==200&&res.data){
                            this.options.subjectMajorCode = res.data.map(m=>{
                                return {label:m.subjectMajorName,value:m.subjectMajorCode}
                            })
                        }
                    })
					Object.keys(this.courseForm).forEach(key => {
							if (response.data[key] || response.data[key] === 0) {
								this.courseForm[key] = response.data[key];
							}else {
								this.courseForm[key] = "";	
							}
						});
					//其他指定人为空时，默认为数组，保证组件功能正常
					if(!this.courseForm.teachersList){
						this.courseForm.teachersList=[];
					}
					if (this.courseForm.college) {
						this.changeDialogCollege(this.courseForm.college);
					}
					this.headTeacherCondition = {
						codeList: [this.courseForm.headTeacher]
					};
					this.teacherCondition = {
						codeList: this.courseForm.teachersList
					};
					this.managerDeptId = this.queryForm.managerDeptId;
					if (type == "edit") {
						this.heardTitle = this.$t("course.updateCourse");
						this.pathKey = "edit";
						this.showCourseCode = false
					} else if (type == "detail") {
						this.heardTitle = this.$t("course.courseDetails");
						this.pathKey = "check";
						if(response.data.code){
							this.showCourseCode = true
						}else{
							this.showCourseCode = false
						}
					}
				}
			});
		},
		//单行删除
		courseDelete(row) {
			if (
				row.status == this.courseStatus.CHECKING ||
				row.status == this.courseStatus.PUBLISH
			) {
				this.$message({
					type: "info",
					message: this.$t("course.deleteCourseFailure")
				});
				return;
			}
			// this.$confirm(
			// 	this.$t("course.confirmDeleteTip"),
			// 	this.$t("message.prompt"),
			// 	{
			// 		confirmButtonText: this.$t("message.confirm"),
			// 		cancelButtonText: this.$t("message.cancel"),
			// 		type: "warning"
			// 	}
			this.$delConfirm().then(() => {
				this.confirmDelete({ idSet: [row.id] });
			});
		},
		//批量删除，课程状态只能为草稿、禁用
		showDeleteDialog() {
			if (this.chooseCourses.length == 0) {
				this.$noSelectAlert();
				// this.$message({
				// 	type: "info",
				// 	message: this.$t("course.notSelectTip")
				// });
				return;
			}
			if (
				!this.chooseCourses.every(
					c =>
						c.status == null ||
						c.status == this.courseStatus.DISABLE ||
						c.status == this.courseStatus.DRAFT
				)
			) {
				this.$message({
					type: "info",
					message: this.$t("course.deleteCourseFailure")
				});
				return;
				/* <i class="el-icon-delete"></i> */
			}
			// this.$confirm(
			// 	this.$t("course.confirmDeleteTip"),
			// 	this.$t("message.prompt"),
			// 	{
			// 		confirmButtonText: this.$t("message.confirm"),
			// 		cancelButtonText: this.$t("message.cancel"),
			// 		type: "warning"
			// 	}
			this.$delConfirm().then(() => {
				this.confirmDelete({
					idSet: this.chooseCourses.map(c => c.id)
				});
			});
		},
		//确定删除
		confirmDelete(data) {
			deleteCourse(data).then(response => {
				if (response.code == 200) {
					this.$message({
						type: "success",
						message: this.$t("common.tips.deleteSuccess")
					});
					this.onSubmit();
				} else {
					throw response.code;
				}
			});
		},
		showAddDialog() {
			this.heardTitle = this.$t("course.addCourse");
			//this.editCourseId = "";
			this.managerDeptId = this.queryForm.managerDeptId;
			this.courseForm = JSON.parse(JSON.stringify(defaultCourseForm));
			this.options.subjectMajorCode = [];
			this.options.appointUserCode = [];
			this.pathKey = "add";
			this.showCourseCode = false;
		},
		down() {
			getpath(this.queryForm.managerDeptId).then(res => {
				if (res.code == 200) {
					window.open(
						"/api/commonservice/obsfile/downloadfile?objectkey=" +
							res.data
					);

					this.showUploadDialog = false;
				} else {
					throw response.code;
				}
			});
		},
		exportExcel() {
			let loading = this.$loading({
				lock: true,
				text: "Loading",
				spinner: "el-icon-loading",
				background: "rgba(255, 255, 255, .48)"
			});
			let data=_.cloneDeep(this.queryForm);
            data.idSet = this.chooseCourses.map(c => c.id);
			generateExcel(data).then(res => {
				if (res.code == 200) {
					this.delayRequest(res.data.key, loading);
				}
			});
		},
		async delayRequest(key, loading) {
			await new Promise(resolve => setTimeout(resolve, 5000));
			examinationStudentsApi.getReportStatus(key)
				.then(res => {
					if (res.code == 200 && res.data.status) {
						loading.close();
						let path = examinationStudentsApi.exportUrl + res.data.path;
                        window.location.href = path;
					} else {
						this.delayRequest(key, loading);
					}
				})
				.catch(err => {
					loading.close();
					throw err;
				});
		},
		//审核
		checkCourse(row) {
			this.$eduConfirm("您确定要提交吗？", this.$t('message.submit')).then(() => {
				apporoveCourse(
				row.id,null
			).then(res => {
				if (res.code == 200) {
					this.$message({
						type: "success",
						message: this.$t("course.operateSuccess")
					});
					this.onSubmit();
				}
			});
			});
		},		
		getStatusText(row) {
			let val=row.status;
			if (val == this.courseStatus.DISABLE)
				return this.$t("message.reject");
			if (val == this.courseStatus.DRAFT)
				return this.$t("message.toBeSubmitted");			
			if (val == this.courseStatus.PUBLISH)
				return this.$t("message.pass");
			if (val == this.courseStatus.CHECKING){
				let obj = this.options.status.find(opt => opt.value == ("2"+row.condition))
				return obj?obj.label:this.$t("message.checkPending");
			}	
			return "";
		},
		getNameByLanguage(obj) {
			let lang = this.$store.getters.language || "cn";
			if (lang == "cn") {
				return obj.name;
			} else {
				return obj.nameEn;
			}
		},
		changeDialogCollege(val) {
			findListByFaculty({ faculty: val }).then(res => {
				this.options.teacherList = res.data;
			});
		},
		back() {
			this.pathKey = "main";
		}
	}
};
</script>

